/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beatbox;
//TODO: Finish and add example playback mechanism
import javafx.scene.*;
import javafx.scene.shape.*;
import com.illposed.osc.*;
import java.net.*;
import javafx.scene.paint.*;
import javafx.scene.input.*;

import beatbox.ADCListener;

/**All the stuff for getting info from chuck
 *
 * @author Kyle
 */
def receivePort = 6448;
var receiver = new OSCPortIn(receivePort);
 //getting adc.last
 public def ADC = {
       var lstn = new ADCListener();
       var result = ADCListenerAdapter{javaADCListener: lstn};
       receiver.addListener("/monitorLevel", lstn);
       receiver.startListening();
       result;
    }

//for getting the examples from chuck
 public def exampleQueue = {
       var lstn = new FeatureListener();
       var result = FeatureListenerAdapter{javaFeatureListener: lstn};
       receiver.addListener("/oscCustomFeatures", lstn);
       receiver.startListening();
       result;
    };

//Plays back the recorded example with the specified id
public function playExample(i:Integer) {
    var sender = new OSCPortOut(InetAddress.getByName("localhost"), 6450);
    var args: Integer[];
    args = [i];
    var msg = new OSCMessage("/playExample", args);
    try {
        sender.send(msg);
        println("playing example {i} ""{msg.getAddress()}");
     } catch (e) {
        println("Couldn't send playExample message");
     }
}
